package org.example.exception;

import com.sun.javaws.IconUtil;
import org.example.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLOutput;

@ControllerAdvice

public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("全局————————————————");
        return Result.fail().message("执行了全局异常处理");
    }
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public Result error(ArithmeticException e){
        e.printStackTrace();
        System.out.println("特定————————————————————————————");
        return Result.fail().message("执行了特定异常处理");
    }
    @ExceptionHandler(GuiGuException.class)
    @ResponseBody
    public Result error(GuiGuException e){
        e.printStackTrace();
        System.out.println("自定义————————————————————————————");
        return Result.fail().code(e.getCode()).message(e.getMsg());
    }
}
